package com.ruoyi.produce.base.procedure.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.produce.base.procedure.domain.Procedure;
import com.ruoyi.produce.base.procedure.service.IProcedureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工序管理
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/produce/procedure")
@Api(value = "工序管理信息模块", tags = "工序管理接口")
public class ProcedureController extends BaseController {
    @Autowired
    private IProcedureService iProcedureService;


    /**
     * 获取工序管理列表
     * @param procedure
     * @return
     */
    @ApiOperationSupport(includeParameters = {"ProducePlanOutsource.procedureId", "ProducePlanOutsource.procedureName", "ProducePlanOutsource.createTime"})
    @ApiOperation(value = "获取工序管理列表",notes = "查询所有工序管理信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody Procedure procedure){

        startPage();
        List<Procedure> procedureList = iProcedureService.selectProcedureList(procedure);

        return getDataTable(procedureList);
    }

    /**
     * 导出工序管理
     * @param procedure
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody Procedure procedure)
    {
        List<Procedure> procedureList = iProcedureService.selectProcedureList(procedure);
        ExcelUtil<Procedure> util = new ExcelUtil<Procedure>(Procedure.class);
        return util.exportExcel(procedureList, "工序管理数据");
    }

    /**
     * 新增工序管理
     * @param procedure
     * @return
     */
    @ApiOperation(value = "新增工序管理", notes = "新增工序管理")
    @ApiImplicitParam(name = "procedure", value = "新增工序管理", dataType = "Procedure")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody Procedure procedure){

        return toAjax(iProcedureService.insertProcedure(procedure));
    }

    /**
     * 修改工序管理
     * @param procedure
     * @return
     */
    @ApiOperation(value = "修改工序管理", notes = "修改工序管理")
    @ApiImplicitParam(name = "procedure", value = "修改工序管理", dataType = "Procedure")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody Procedure procedure)
    {
        return toAjax(iProcedureService.updateProcedure(procedure));
    }

    /**
     * 删除工序管理
     * 仅修改删除标志位
     * @param procedure
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Procedure procedure)
    {

        return toAjax(iProcedureService.updateProcedureDeleteFlag(procedure));
    }
}
